import MathUtil from '@/MathUtil';
import SelectUtil from '@/SelectUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 狂怒冲锋
 **/
export default class ZS_FuryAssaul extends AbilityBase {
    static instance: ZS_FuryAssaul;
    damagePool: Map<unit, unit[]> = new Map<unit, unit[]>();
    constructor(id: string = 'Aknf') {
        super(id);
        ZS_FuryAssaul.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let cx = GetUnitX(source),
            cy = GetUnitY(source);
        let dis = MathUtil.distanceBetweenPoints(tarX, tarY, cx, cy);
        let ag = MathUtil.angleBetweenCoords(cx, cy, tarX, tarY);
        let time = dis / 1000;
        this.damagePool.set(source, []);
        MovementCommon.hitFly({
            target: source,
            caster: source,
            distance: dis,
            angle: ag,
            time,
            maxHeight: 0,
            onInterval: this.onInterval.bind(this),
            onEnd: this.onEnd.bind(this),
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    onInterval(p: HitFlyConfig) {
        // DestroyEffect(AddSpecialEffect('Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageDeathCaster.mdl', GetUnitX(p.target), GetUnitY(p.target)));
        DestroyEffect(AddSpecialEffect('Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl', GetUnitX(p.target), GetUnitY(p.target)));
        let es = SelectUtil.getEnemyUnitsInRange(p.caster, 175);
        for (let e of es) {
            if (this.damagePool.get(p.caster)?.includes(e)) {
                continue;
            }
            this.damagePool.get(p.caster).push(e);
            StunSystemIntance.stun(e, 2, p.caster);
            let lv = this.getAbilityLevel(p.caster);
            let dmg = 35 * lv + UnitCommon.取攻击(p.caster) * (0.75 + 0.25 * lv);
            DamageSystemInstance.applyEarthDamage(e, p.caster, dmg, this.id);
        }
        return true;
    }
    onEnd(p: HitFlyConfig) {
        this.damagePool.delete(p.caster);
    }
}
